<template>
	<div class="nav">
		<div class="navTitle">
			<div class="ntLogo">
				<img v-if="baseInfo.image && baseInfo.image.preImgUrl" :src="baseInfo.image.preImgUrl" width="74" height="74" style="border-radius: 50%;" />
				<img v-else="baseInfo.image || !baseInfo.image.preImgUrl" src="./images/logo.png" width="74" height="74" />
				<span class="appState" v-show="baseInfo.status || baseInfo.status === 0 || baseInfo.status === 1 || baseInfo.status === 2">
					{{baseInfo.status | statusMapping}}
				</span>
			</div>
			<div class="appName">{{baseInfo.name ? getName(baseInfo.name) : '小程序名称'}}</div>
		</div>
		<div class="navContent">
			<div>
				<div class="navList">
					<router-link v-for="item in navList" :to="item.to" :key="item.name">
						<div class="navTab" :class="[$route.path.indexOf(item.to) != -1 ? 'active' : '']">
							<i class="navTabIco" :class="[item.icon]"></i>
							<span>{{item.name}}</span>
						</div>
					</router-link>
				</div>
			</div>
		</div>
		<div class="navFooter">
			<div>
				<div class="actionBtn" @click="issueShow = true">发布小程序</div>
				<div class="hotline">
					客服QQ<br>
					<span>3479149702</span>
				</div>
			</div>
		</div>
		<!-- issue -->
    <div class="commonMain issue" v-show="issueShow">
    <div class="shadow"></div>
    <div class="coMin">
      <button type="button" class="closeBtn" @click="issueShow = false"></button>
      <div class="issueContent">
        <div class="issueTitle">
          <img src="./images/wx.png">
          <h2>微信小程序授权</h2>
        </div>
        <div class="issueTxt">
          首次发布将需要进行小程序授权，请使用小程序管理员账号进行操作
        </div>
        <div class="issueBtn">
          <button type="button" class="registerBtn" @click="openRegisterView">注册小程序账号</button>
          <button type="button" class="accreditBtn" @click="wechatAuth">我已有账号，前往授权</button>
        </div>
        <div class="toHelp">
          <a href="javascript:;" class="helpLink" @click="goAnswer">教程：如何在微信注册小程序？</a>
        </div>
      </div>
    </div>
  </div>
    <!-- issue end -->
	</div>
</template>

<script type="javascript/ecmascript6">
import fetch from '@/fetch'

export default{
	name: 'navcomponent',
	props: ['baseInfo'],
	data () {
	  return {
	  	issueShow: false,
	  	navList: [
	  	  {
	  	  	icon: 'basicIco',
	  	  	to: '/basic',
	  	  	name: '基本信息'
	  	  },
	  	  {
	  	  	icon: 'goodsIco',
	  	  	to: '/goods',
	  	  	name: '商品管理'
	  	  },
	  	  {
	  	  	icon: 'storesIco',
	  	  	to: '/stores',
	  	  	name: '门店管理'
	  	  },
	  	  {
	  	  	icon: 'helpIco',
	  	  	to: '/help',
	  	  	name: '帮助中心'
	  	  }
	  	]
	  }
	},
	filters: {
	  statusMapping (status) {
	  	let text = ''
	  	switch (status) {
	  	  case 0:
	  	    text = '未开通'
	  	    break
	  	  case 1:
	  	    text = '审核中'
	  	    break
	  	  case 2:
	  	    text = '审核失败'
	  	    break
	  	  default: 
	  	    text = '未知状态'
	  	    break
	  	}
	  	return text
	  }
	},
	methods: {
	  getName (name) {
	  	return name.length > 10 ? (name.substr(0, 10) + '...') : name
	  },
	  wechatAuth () {
	  	fetch.send('/merchant/publishXcx').then(res => {
	  	  if (res.respCode === '000000') {
	  	  	window.open(res.result)
	  	  } else {
	  	  	this.$noty.error(res.respDesc ? res.respDesc : '获取基础信息失败')
	  	  }
	  	})
	  },
	  openRegisterView () {
	  	window.open('https://mp.weixin.qq.com/')
	  },
	  goAnswer () {
	    this.$router.push({
	      path: '/help/answer/1'
	    })
	    this.issueShow = false
	  }
    }
}

</script>
<style type="text/css" scoped>
.nav{
	display: flex;
	flex: 0 0 auto;
	flex-direction: column;
	float: none;
	width: 240px;
	height: 100vh;
	padding: 0;
	overflow: hidden;
	color: #fff;
	background: #484848;
}

.navTitle{
	flex: 0 0 auto;
	padding: 56px 10px 50px;
}
.ntLogo{
	position: relative;
	width: 74px;
	height: 74px;
	background: #242424;
	border-radius: 50px;
	padding: 4px;
	border: 2px solid #333;
	box-shadow: 1px 1px 5px 1px #555;
	margin: 0 auto;
}
.appState{
	position: absolute;
	bottom: -8px;
	left: 58px;
	display: block;
	flex: 0 0 auto;
	width: 50px;
	height: 18px;
	padding: 3px;
	background: #FF9500;
	border-radius: 3px;
	font-size: 14px;
	line-height: 18px;
	text-align: center;
	letter-spacing: 1px;
}
.appName{
	width: 100%;
	padding-top: 25px;
	font-size: 16px;
	letter-spacing: .5px;
	text-align: center;
}

.navContent{
	flex: 1 1 0;
	padding-bottom: 20px;
}
.navTab{
	position: relative;
	padding: 28px 0 28px 54px;
	overflow: hidden;
	cursor: pointer;
}
.navTabIco{
	width: 22px;
	height: 22px;
	float: left;
	vertical-align: middle;
}
.basicIco{
	background: url('images/basic.png') no-repeat;
	background-size: 22px 22px;
}
.goodsIco{
	background: url('images/goods.png') no-repeat;
	background-size: 22px 22px;
}
.storesIco{
	background: url('images/stores.png') no-repeat;
	background-size: 22px 22px;
}
.helpIco{
	background: url('images/help.png') no-repeat;
	background-size: 22px 22px;
}
.navTab span{
	float: left;
	margin-left: 12px;
	color: #fff;
	font-size: 14px;
	line-height: 22px;
	letter-spacing: 1px;
}
.active{
	background: #292929;
	border-left: 4px solid #F54D4F;
}

.navFooter{
	flex: 0 0 auto;
	text-align: center;
}
.navFooter>div{
	padding: 0 30px;
}
.actionBtn{
	width: 180px;
	height: 48px;
	background: #F54D4F;
	border: 0;
	border-radius: 5px;
	font-size: 18px;
	line-height: 48px;
	cursor: pointer;
	letter-spacing: 1px;
}
.hotline{
	width: 100%;
	padding: 12px 0;
	margin: 25px 0 40px;
	border: 1px solid #343434;
	border-radius: 5px;
	font-size: 16px;
	line-height: 26px;
	letter-spacing: 2px;
}
.hotline span{
	letter-spacing: 1px;
}

.commonMain{
		display: block;
	  	z-index: 9999999999;
	}
	.coMin{
		width: 450px;
		height: 428px;
		padding: 45px 45px 15px;
		box-sizing: border-box;
		background: #fff;
		border-radius: 5px;
		position: fixed;
		top: 50%;
		left: 50%;
		margin-top: -214px;
		margin-left: -225px;
		z-index: 9999;
	}
	.closeBtn{
		width: 20px;
		height: 20px;
		background: url('images/closeWx.png') no-repeat transparent;
		background-size: cover;
		border: none;
		position: absolute;
		right: 20px;
		top: 15px;
		outline: none;
		cursor: pointer;
	}
	.issueContent{
		font-size: 16px;
		color: #8f8f8f;
		text-align: center;
		line-height: 22px;
	}
	.issueTitle img{
		width: 22%;
	}
	.issueTitle h2{
		font-size: 18px;
		color: #333;
		margin: 15px 0;
		font-weight: 600;
		letter-spacing: 1px;
	}
	.issueBtn{
		padding: 30px 0 20px;
	}
	.issueBtn button{
		width: 100%;
		height: 40px;
		background: #fff;
		border-radius: 4px;
		font-size: 16px;
		color: #8f8f8f;
		line-height: 40px;
		letter-spacing: .5px;
		border: 1px solid #dedede;
		margin-bottom: 25px;
		outline: none;
		cursor: pointer;
	}
	.issueBtn button.registerBtn{
		color: #fff;
		background: #F54D4F;
		border: none;
	}
	.helpLink{
		line-height: 18px;
		font-size: 12px;
		color: #298beb;
	}
	.shadow{
	  	width: 100%;
	  	height: 100%;
	  	background: rgba(0, 0, 0, .3);
	  	position: fixed;
	  	top: 0;
	  	left: 0;
	  	bottom: 0;
	  	right: 0;
	}
</style>